﻿using APH.Parl2.DataAccess;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace TestProject
{
    
    
    /// <summary>
    ///This is a test class for DataAccessHelperTest and is intended
    ///to contain all DataAccessHelperTest Unit Tests
    ///</summary>
    [TestClass()]
    public class WriteHelperTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for GetDocumentById
        ///</summary>
        [TestMethod()]
        public void GetDocumentByIdTest()
        {
            var Id = WriteHelper.CreateDocument("John Smith", "<xml/>");
            var expectedId = Id;
            var actual = WriteHelper.GetDocumentById(Id);
            Assert.AreEqual(expectedId, actual.Id);
        }

        /// <summary>
        ///A test for CreateDocument
        ///</summary>
        [TestMethod()]
        public void CreateDocumentTest()
        {
            var author = "Author"; 
            var data = "<xml/>"; 
            var actual = WriteHelper.CreateDocument(author, data);
            var doc = WriteHelper.GetDocumentById(actual);
            Assert.AreEqual(doc.Id, actual);
        }

        /// <summary>
        ///A test for DeleteDocument
        ///</summary>
        [TestMethod()]
        public void DeleteDocumentTest()
        {
            var id = WriteHelper.CreateDocument("John Smith", "<xml/>");
            WriteHelper.DeleteDocument(id);
            var doc = WriteHelper.GetDocumentById(id);
            Assert.IsNull(doc);
        }

        /// <summary>
        ///A test for UpdateDocumentContent
        ///</summary>
        [TestMethod()]
        public void UpdateDocumentContentTest()
        {
            var id = WriteHelper.CreateDocument("John Smith", "<xml/>");
            string data = "<xml></xml>";
            WriteHelper.UpdateDocumentContent(id, data);
            var doc = WriteHelper.GetDocumentById(id);
            Assert.AreEqual(doc.Data, data);
        }

        /// <summary>
        ///A test for ConnectionString
        ///</summary>
        [TestMethod()]
        public void ConnectionStringTest()
        {
            string expected = "metadata=res://*/ReadModel.ReadModel.csdl|res://*/ReadModel.ReadModel.ssdl|res://*/ReadModel.ReadModel.msl;provider=System.Data.SqlClient;provider connection string=\"Data Source=localhost;Initial Catalog=Parl2_Read;Integrated Security=True;MultipleActiveResultSets=True\"";
            string actual = ReadHelper.ConnectionString;
            Assert.AreEqual(expected, actual);
        }
    }
}
